package com.choichumgming.rentcat.service.Impl;

import com.choichumgming.rentcat.common.api.CommonResult;
import com.choichumgming.rentcat.dao.OrderReturnParamDao;
import com.choichumgming.rentcat.dto.OrderProcessParam;
import com.choichumgming.rentcat.dto.OrderReturnParam;
import com.choichumgming.rentcat.mapper.OmsOrderItemMapper;
import com.choichumgming.rentcat.mapper.OmsOrderMapper;
import com.choichumgming.rentcat.model.OmsOrder;
import com.choichumgming.rentcat.model.OmsOrderExample;
import com.choichumgming.rentcat.service.OmsSellerOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


/**
 * @ClassName OmsSellerOrderServiceImpl
 * @Description : 卖家订单Service
 * @Author : choichumgming
 * @Date : 5/3/2020 16:58
*/
@Slf4j
@Service
public class OmsSellerOrderServiceImpl implements OmsSellerOrderService {
    @Autowired
    OmsOrderMapper omsOrderMapper;

    @Autowired
    OmsOrderItemMapper orderItemMapper;

    @Autowired
    private OrderReturnParamDao orderReturnParamDao;

    /**
     * @Description : 处理买家订单信息 添加订单号 订单信息,修改订单状态
     * 完善订单号等信息
     *'订单状态：0->待付款；1->待发货；2->已发货；3->已完成；4->已评论 5->已关闭；6->无效订单,
     * @param orderProcessParam
     * @Return : com.choichumgming.rentcat.common.api.CommonResult
     * @Author : choichumgming
     * @Date : 6/3/2020 13:42
    */
    @Override
    public int processOrder(OrderProcessParam orderProcessParam) {
        OmsOrder omsOrder = new OmsOrder();
        omsOrder.setOrderId(orderProcessParam.getOrderId());
        omsOrder.setDeliveryCompany(orderProcessParam.getDeliveryCompany());
        omsOrder.setDeliverySn(orderProcessParam.getDeliverySn());
        omsOrder.setDeliveryTime(new Date());
        omsOrder.setStatus(2);
        OmsOrderExample omsOrderExample = new OmsOrderExample();
        omsOrderExample.createCriteria().andOrderIdEqualTo(orderProcessParam.getOrderId());
        return omsOrderMapper.updateByExampleSelective(omsOrder, omsOrderExample);
    }

    /**
     * @Description : 获得作为卖家出租东西的订单
     * @Return : java.util.List<com.choichumgming.rentcat.model.OmsOrder>
     * @Author : choichumgming
     * @Date : 6/3/2020 13:42
    */
    @Override
    public CommonResult getSellerList(Long userId) {
        List<OrderReturnParam> orderReturnParamList = orderReturnParamDao.getSellerOrderList(userId);

        return CommonResult.success(orderReturnParamList);

    }


    /**
     * @Description : 删除订单
     *
     * @param orderId
     * @Return : void
     * @Author : choichumgming
     * @Date : 6/3/2020 13:42
    */

    @Override
    public void deleteOrder(Long orderId) {
        omsOrderMapper.deleteByPrimaryKey(orderId);
    }

}
